package com.example.demo.entity;


import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("user")
@Document(indexName = "user", createIndex = true)
public class UserEntity {
    @Id
    private Long id;
    private String name;
    private Integer age;
    private String email;

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        if (id != null) {
            sb.append("\"id\":").append(id).append(",");
        }
        if (name != null) {
            sb.append("\"name\":\"").append(name).append("\",");
        }
        if (age != null) {
            sb.append("\"age\":").append(age).append(",");
        }
        if (email != null) {
            sb.append("\"email\":\"").append(email).append("\",");
        }
        if (sb.lastIndexOf(",") != -1)
            sb.deleteCharAt(sb.lastIndexOf(","));
        sb.append('}');
        return sb.toString();
    }
}
